<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('rd_alarm_work', function (Blueprint $table) {
            $table->comment('工单');
            $table->bigIncrements('id');
            $table->string('title', 255)->comment('工单标题');
            $table->text('content')->comment('工单内容');
            $table->unsignedTinyInteger('status')->default(1)->comment('工单状态1:待处理2:处理中3:待复核4:复核完成5:关闭');
            $table->unsignedBigInteger('stand_id')->comment('站点ID');
            $table->unsignedInteger('type')->comment('工单类型1:AI告警工单2:AI隐患工单3:人工提报工单');
            $table->unsignedBigInteger('user_id')->nullable()->comment('工单处理人ID');
            $table->unsignedInteger('expire_times')->default(0)->comment('延期次数');
            $table->timestamp('expire_at')->comment('整改限期');
            $table->unsignedTinyInteger('priority')->comment('工单优先级1:普通2:紧急3:非常紧急');
            $table->unsignedTinyInteger('related_type')->comment('工单关联类型1:告警2:隐患3:其他');
            $table->unsignedBigInteger('related_id')->nullable()->comment('关联ID');
            $table->json('extra')->nullable()->comment('工单附加信息');
            $table->authorBy();
            $table->timestamps();
            $table->index('user_id', 'idx_user_id');
            $table->index('stand_id', 'idx_stand_id');
            $table->index('status', 'idx_status');
            $table->index('type', 'idx_type');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('rd_alarm_work');
    }
};